<template>
	<view>
		<view class="top-bg">
			<text>CONTRA</text>
		</view>
		<view class="info-con">
			<view class="info">
				<view class="title" @click="backMySign"><text class="iconfont iconfanhui" style=""></text>返回列表</view>
				<view class="name">
					<view>
						<text>产品名称：</text>
						<text>{{ contractInfo.class_name }}</text>
					</view>
					<view>
						<text>课包时效：</text>
						<text>{{ contractInfo.time_limit }}个月</text>
					</view>
					<view>
						<text>签约门店：</text>
						<text>{{ contractInfo.store_name }}</text>
					</view>
					<view>
						<text>发起签约：</text>
						<text>{{ contractInfo.counselor_englishname }}（{{ contractInfo.counselor_realname }}）</text>
					</view>
					<view style="display: inline-block;">
						<text>赠课信息：</text>
						<text>基础赠课 {{contractInfo.common_give}}节<text v-show="contractInfo.sign_gift_give_class_num">+礼物换课{{contractInfo.sign_gift_give_class_num}}节</text><text v-show="contractInfo.principal_give">+校长特批{{contractInfo.principal_give}}节</text></text>
					</view>
					<!-- <view style="display: inline-block;">
						<text>签约礼品：</text>
						<text v-show="contractInfo.sign_gift_name">{{contractInfo.sign_gift_name}}<text v-show="contractInfo.sign_gift_give_class_num">（已换课）</text><text v-show="contractInfo.principal_gift_name">+{{contractInfo.principal_gift_name}}（校长特批）</text></text>
						<text v-show="!contractInfo.sign_gift_name">-</text>
					</view> -->
					<view style="display: inline-block;" v-for="(item, index) in contractInfo.sign_gift_list" :key="index">
						<text>签约礼品{{ index+1 }}：</text>
						<text v-show="item.name">{{item.name}}<text v-show="item.give">（已换课{{item.class_num}}节）</text></text>
						<text v-show="!item.name">-</text>
					</view>
					<view class="xiao-zhang" style="display: inline-block;" v-for="(item, index) in contractInfo.principal_gift_list" :key="index + 'xiao'">
						<text>特批礼品{{ index+1 }}：</text>
						<text v-show="item.name">{{item.name}}<text v-show="item.give">（已换课{{item.class_num}}节）</text></text>
						<text v-show="!item.name">-</text>
					</view>
				</view>
			</view>
		</view>
		<!-- 进度记录 -->
		<view class="progress" style="margin-top: 60rpx;">
			<view style="height: 76rpx;">
				<view class="title">
					<view class="contract-title">进度记录</view>
					<view class="yellow-line"></view>
				</view>
			</view>
			<view class="progress-con">
				<GymProgress :isActive='isActive' :finishTime="finishTime"></GymProgress>
			</view>
		</view>
		<!-- 服务人员 -->
		<!-- <view class="progress" style="margin: 40rpx auto 40rpx;">
			<view style="height: 76rpx;">
				<view class="title">
					<view class="contract-title">服务人员</view>
					<view class="yellow-line"></view>
				</view>
			</view>
			<view class="teacher-con">
				<text>教学服务INS：amily</text>
				<text>教学服务GB：amily</text>
				<text>教学服务GA：amily</text>
				<text>教学服务GC：amily</text>
			</view>
		</view> -->
		<view class="btn" @click="navTo(contractInfo.status)">
			<Dbutton :btnTxt="btnTxt3" v-if="contractInfo.status === 1 && contractInfo.company_status === 0"></Dbutton>
			<Dbutton :btnTxt="btnTxt" v-if="contractInfo.status === 1 && contractInfo.company_status === 1"></Dbutton>
			<Dbutton :btnTxt="btnTxt1" v-if="contractInfo.status === 0"></Dbutton>
			<Dbutton :btnTxt="btnTxt2" v-if="contractInfo.status === 3 || contractInfo.status === 4"></Dbutton>
		</view>
	</view>
</template>

<script>
	import GymProgress from '../../components/progress.vue'
	import Dbutton from '../../components/button.vue'
	import { findInfo, viewContract } from '../../api/serviceApi.js'
	import { companySign } from '../../api/identificationApi.js'
	import { getUserState } from '../../api/indexApi.js'
	export default {
		data() {
			return {
				isActive: -1,
				btnTxt: '生成签约二维码',
				btnTxt1: '继续',
				btnTxt2: '查看合同',
				btnTxt3: '立即签署',
				finishTime: [],
				id: '',
				contractInfo: {}
			}
		},
		components: {
			GymProgress,
			Dbutton
		},
		computed: {
			
		},
		onLoad(option) {
			// console.log(option)
			this.id = option.id
			if (option.transaction_id) {
				setTimeout(() => {
					this._findInfo()
				},1000)
			} else {
				this._findInfo()
			}
		},
		methods: {
			async _findInfo() {
				const params = {id: this.id}
				const res = await findInfo(params)
				console.log(res)
				this.contractInfo = res.data.data
				if (this.contractInfo.company_sign_time) {
					this.finishTime[0] = this.contractInfo.company_sign_time
					this.isActive = 1
				}
				if (this.contractInfo.sign_time) {
					this.finishTime[1] = this.contractInfo.sign_time
					this.isActive = 2
				}
				if (this.contractInfo.paytime) {
					this.finishTime[2] = this.contractInfo.paytime
					this.isActive = 3
				}
				if (this.contractInfo.audit_time) {
					this.finishTime[3] = this.contractInfo.audit_time
					this.isActive = 4
				}
				this.finishTime = [...this.finishTime]
			},
			async navTo(status) {
				console.log(status)
				if (status === 0) {
					uni.navigateTo({
						url: `../identification/baseInfo?id=${this.contractInfo.id}`
					})
				} else if (status === 1 && this.contractInfo.company_status === 1) {
					uni.navigateTo({
						url: `../share/share?id=${this.contractInfo.id}`
					})
				} else if (status === 1 && this.contractInfo.company_status === 0) {
					// 判断是否认证
					const res = await getUserState()
					// console.log(res)
					console.log("立即签署去")
					if (res.data.data.status !== 2) {
						uni.showToast({title: '未认证',icon: 'none'})
						setTimeout(() => {
							// window.location.href = res.data.data.url
							uni.navigateTo({url: '../real-name/real-name'})
						}, 1500)
					} else {
						const result = await companySign({id: this.contractInfo.id})
						window.location.href = result.data.data.url
					}
				} else if (status === 3 || status === 4) {
					console.log('状态' +status + '查看合同')
					this._viewContract()
				} 
				// switch (status) {
				// 	case 0: 
				// 		console.log(12)
				// 		uni.navigateTo({
				// 			url: `../identification/baseInfo?id=${this.contractInfo.id}`
				// 		})
				// 		break
				// 	case 1: 
				// 		uni.navigateTo({
				// 			url: `../share/share?id=${this.contractInfo.id}`
				// 		})
				// 		break
				// 	case 3: 
				// 		console.log('查看合同,已付款')
				// 		this._viewContract()
				// 		break
				// 	case 4:
				// 		console.log('查看合同,已完成')
				// 		this._viewContract()
				// 		break
				// }
			},
			backMySign() {
				uni.navigateTo({
					url: './adviserSignList'
				})
			},
			async _viewContract() {
				const res = await viewContract({id: this.contractInfo.id})
				console.log(res)
				window.location.href = res.data.data.view_url
			}
		},
		mounted() {
			
		}
	}
</script>

<style lang="scss" scoped>
	.top-bg {
		height: 300rpx;
		background-color: #fedb0d;
		text-align: center;
		text {
			font-size: 152rpx;
			font-weight: 800;
			color: rgba(255, 255, 255, .2);
		}
	}
	.info-con {
		font-family: PingFangSC-Regular;
		// height: 410rpx;
		position: relative;
		.info {
			// position: absolute;
			// left: 50%;
			// top: -250rpx;
			transform: translateX(4%);
			margin-top: -250rpx;
			.title {
				font-size: 38rpx;
				color: #191919;
				font-weight: 600;
				padding: 0 0 20rpx 0;
				display: flex;
				align-items: center;
				text {
					font-size: 44rpx;
					padding-right: 10rpx;
				}
			}
			.name {
				width: 690rpx;
				// height: 400rpx;
				background-color: #fff;
				box-shadow: 0 8rpx 68rpx 0 rgba(0, 0, 0, 0.1);
				border-radius: 2rpx;
				display: flex;
				flex-direction: column;
				justify-content: space-around;
				view {
					box-sizing: border-box;
					font-size: 30rpx;
					padding: 16rpx 40rpx;
					display: flex;
					text:nth-child(2) {
						padding-left: 6rpx;
					}
				}
				view:nth-child(1) {
					padding-top: 32rpx;
				}
				view:last-child {
					padding-bottom: 32rpx;
				}
			}
		}
	}
	.progress {
		.title {
			margin-left: 50rpx;
			font-family: PingFangSC-Semibold;
			font-size: 38rpx;
			font-weight: 600;
			color: #191919;
			position: relative;
			.yellow-line {
				width: 168rpx;
				height: 14rpx;
				background-color: #fedb0d;
				position: absolute;
				left: -6rpx;
				bottom: -52rpx;
			}
			.contract-title {
				position: absolute;
				left: 0;
				top: 0;
				z-index: 2;
			}
		}
		.progress-con,.teacher-con {
			box-sizing: border-box;
			margin: 0 auto;
			// padding: 34rpx 38rpx;
			width: 690rpx;
			background-color: #fff;
			box-shadow: 0 8rpx 68rpx 0 rgba(0, 0, 0, 0.1);
			border-radius: 2rpx;
		}
		.teacher-con {
			padding: 30rpx 40rpx;
			display: flex;
			flex-wrap: wrap;
			justify-content: space-between;
			text {
				font-family: PingFangSC-Regular;
				font-size: 30rpx;
				color: #020202;
				padding-bottom: 16rpx;
			}
			text:nth-last-child(1),text:nth-last-child(2) {
				padding-bottom: 0;
			}
		}
	}
	.btn {
		margin: 40rpx 0;
	}
</style>
